package solved;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;

/*
 ID:	liluyan1
 LANG:	JAVA
 TASK:	milk2
 */
public class milk2 {
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new FileReader("milk2.in"));
		int[] max = new milk2().max(f);
		
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
				"milk2.out")));
		out.println(max[0] + " " + max[1]);
		out.close();
		System.exit(0);
	}
	
	private int[] max(BufferedReader f) throws IOException {
		int N = Integer.parseInt(f.readLine());
		Milk[] m = new Milk[N];
		for (int i=0; i<N; i++) {
			String[] line = f.readLine().split(" "); 
			m[i] = new Milk(Integer.parseInt(line[0]), 
					Integer.parseInt(line[1]));
		}
		
		Arrays.sort(m, new Comparator<Milk>() {
			public int compare(Milk a, Milk b) {
				return a.begin - b.begin;
			}
		});
		
		int span = m[0].end - m[0].begin;
		int gap = 0;
		int begin = m[0].begin;
		int end = m[0].end;
		
		for (int i=1; i<N; i++) {
			if (m[i].begin > end) {
				gap = Math.max(gap, m[i].begin - end);
				span = Math.max(span, m[i].end - m[i].begin);
				begin = m[i].begin;
				end = m[i].end;
			}
			else {
				if (m[i].end > end) {
					end = m[i].end;
					span = Math.max(span, end - begin);
				}
			}
		}
		
		return new int[]{span, gap};
	}
	
	private class Milk {
		int begin;
		int end;
		public Milk(int begin, int end) {
			this.begin = begin;
			this.end = end;
		}
	}
}
